package com.lemner.ke.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemner.ke.R;
import com.lemner.ke.activity.PlayActivity;
import com.lemner.ke.base.URL;
import com.lemner.ke.bean.VideoTabRvBean;
import com.lemner.ke.util.LoadImageUtils;

import java.util.List;

/**

* 作者：张恺

* 时间：2018/9/25

* 类描述：视频详情页—视频-adapter

*/

public class VideoTabRvAdapter extends com.lemner.ke.base.BaseAdapter<VideoTabRvBean>{
    private Context context;
    public VideoTabRvAdapter(Context context) {
        super(context);
        this.context=context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(layoutInflater.inflate(R.layout.item_video_tab,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myViewHolder=(MyViewHolder) holder;
        final VideoTabRvBean bean=list.get(position);
        if (bean!=null){
            if (null != bean.getCoverpath()) {
                LoadImageUtils.loadRoundImage(URL.BASE_URL + bean.getCoverpath(), myViewHolder.iv_video);
            }
            if (null != bean.getHitnum()) {
                myViewHolder.tv_hit.setText(bean.getHitnum());
            }
            if (null != bean.getTitle()) {
                myViewHolder.tv_title.setText(bean.getTitle());
            }
            myViewHolder.v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(context, PlayActivity.class);
                    intent.putExtra("ids",bean.getIds());
                    context.startActivity(intent);
                }
            });
        }
    }


    public class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView iv_video;
        private TextView tv_hit, tv_title;
        private View v;
        public MyViewHolder(View itemView) {
            super(itemView);
            v=itemView;
            iv_video = itemView.findViewById(R.id.item_video_tab_bg_iv);
            tv_hit = itemView.findViewById(R.id.item_video_tab_hit_tv);
            tv_title = itemView.findViewById(R.id.item_video_tab_title);
        }
    }
}
